package org.jeecg.modules.wlhy.customer.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.constant.enums.ExamineStatusEnum;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.IDUtils;
import org.jeecg.common.util.ImageCompressUtil;
import org.jeecg.common.util.PasswordUtil;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.system.model.CustomerSysLoginModel;
import org.jeecg.modules.third.dongjiang.tax.system.dto.ApiBaseResDTO;
import org.jeecg.modules.third.dongjiang.tax.system.dto.req.publisher.PublisterDTO;
import org.jeecg.modules.third.dongjiang.tax.system.service.DongjiangTaxSystemService;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.third.tosapi.constant.enums.YNEnum;
import org.jeecg.modules.third.tosapi.dto.TosApiBaseResDTO;
import org.jeecg.modules.third.tosapi.dto.customer.CustomerDTO;
import org.jeecg.modules.third.tosapi.service.TosApiService;
import org.jeecg.modules.wlhy.customer.dto.ImportHyCustomerDTO;
import org.jeecg.modules.wlhy.customer.entity.HyCustomer;
import org.jeecg.modules.wlhy.customer.entity.HyCustomerUser;
import org.jeecg.modules.wlhy.customer.mapper.HyCustomerMapper;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerService;
import org.jeecg.modules.wlhy.customer.service.IHyCustomerUserService;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static org.jeecg.modules.third.dongjiang.tax.system.constant.TaxConstant.API_TAX_CUSTOMER_SUBFIX;

/**
 * @Description: hy_customer
 * @Author: jeecg-boot
 * @Date:   2020-11-30
 * @Version: V1.0
 */
@Service
@Slf4j
public class HyCustomerServiceImpl extends ServiceImpl<HyCustomerMapper, HyCustomer> implements IHyCustomerService {

    @Value(value="${customer.roleid}")
    private String customerRoleID;
    @Value(value="${customer.departpid}")
    private String customerDepartpid;

    @Value(value = "${jeecg.path.upload}")
    private String uploadpath;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private ISysDepartService departService;

    @Autowired
    private ISysUserService sysUserService;

//    @Autowired private UserUtil userUtil;

    @Autowired
    private IHyCustomerUserService hyCustomerUserService;

//    @Resource
//    private SysUserRoleMapper sysUserRoleMapper;

    @Resource
    private  DongjiangTaxSystemService dongjiangTaxSystemService;

    @Autowired
    private TosApiService tosApiService;

    @Override
    @Transactional
    public void saveCustomer(HyCustomer hyCustomer) {

        String loginPhone = hyCustomer.getLoginPhone();
        if(StringUtils.isEmpty(loginPhone)){
            throw new JeecgBootException("登陆手机号不能为空");
        }
        if( loginPhone.length() != 11){
            throw new JeecgBootException("登陆手机号应为11位数。");
        }
        if (  !loginPhone.matches(CommonConstant.REGEX_MOBILE)) {
            throw new JeecgBootException("登陆手机号格式错误！");
        }

        if(hyCustomer.getCustomerType().equals("2")){
            if(StringUtils.isEmpty(hyCustomer.getCustomerName())){
                throw new JeecgBootException("客户名称不能为空！");
            }
            if(StringUtils.isEmpty(hyCustomer.getLegalName())){
                throw new JeecgBootException("企业法人姓名不能为空！");
            }
            if(StringUtils.isEmpty(hyCustomer.getLegalPhone())){
                throw new JeecgBootException("法人手机号不能为空！");
            }

            if( hyCustomer.getLegalPhone().length() != 11){
                throw new JeecgBootException("法人手机号应为11位数。");
            }
            if (  !hyCustomer.getLegalPhone().matches(CommonConstant.REGEX_MOBILE)) {
                throw new JeecgBootException("法人手机号格式错误！");
            }

            if(StringUtils.isEmpty(hyCustomer.getCreditCode())){
                throw new JeecgBootException("统一社会信用代码不能为空！");
            }
            if(StringUtils.isEmpty(hyCustomer.getBusinessLicenseExpiredDate())){
                throw new JeecgBootException("营业执照有效期不能为空！");
            }
            if(hyCustomer.getBusinessLicenseExpiredDate().before(new Date())){
                throw new JeecgBootException("营业执照有效期已过期！");
            }
            if(StringUtils.isEmpty(hyCustomer.getBusinessLicenseImg())){
                throw new JeecgBootException("营业执照照片不能为空！");
            }
            //if(StringUtils.isEmpty(hyCustomer.getBusinessLicenseImg2())){
            //    throw new JeecgBootException("营业执照副本不能为空！");
            //}
        }

        if(!StringUtils.isEmpty(hyCustomer.getIdcard() ) &&  hyCustomer.getIdcard().length() != 15 &&
                hyCustomer.getIdcard().length() != 18){
            throw new JeecgBootException("身份证应为15位或者18位。");
        }
        if(!IDUtils.isIDNumber(hyCustomer.getIdcard())){
            throw new JeecgBootException("请填写正确身份证！");
        }
//        if(hyCustomer.getCustomerChannel().equals("2")){
//            if(StringUtils.isEmpty(hyCustomer.getCooperAgreement())){
//                throw new JeecgBootException("合作协议不能为空！");
//            }
//        }

        //如果客户类型=1 个人时，设置客户名称=联系人
        String uname = "";
        if("1".equals(hyCustomer.getCustomerType())){
            uname = hyCustomer.getContactName();
            hyCustomer.setCustomerName(uname);
        }else {
            uname = hyCustomer.getCustomerName();
        }
        //添加部门
        SysDepart sysDepart = new SysDepart();
        sysDepart.setParentId(customerDepartpid);
        sysDepart.setOrgCategory("2");//货主
        sysDepart.setDepartName(uname);
        sysDepart.setDepartOrder(0);
        departService.saveDepartData(sysDepart, uname);

        if(StringUtils.isEmpty(hyCustomer.getUserId())  ){
            //添加用户 ，检查用户是否存在
            SysUser suser = userService.getUserByPhone(loginPhone);
            if(suser != null){
                throw new JeecgBootException("登陆手机号已存在,不能重复注册");
            }

            //添加登陆账号
            SysUser user = new SysUser();
//            String username = loginPhone;//设置登陆账号为手机号
		    String username = sysUserService.createRandomUserName();//随机生成账号
            user.setUType("2");
            user.setUsername(username);
            user.setRealname(uname);
            user.setPhone(loginPhone);
            user.setCreateTime(new Date());//设置创建时间
            String salt = oConvertUtils.randomGen(8);
            user.setSalt(salt);
            user.setPassword("Aa.123456");//设置默认密码123456
            String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
            user.setPassword(passwordEncode);
            user.setOrgCode(sysDepart.getOrgCode());
            user.setStatus(1);
            user.setDelFlag(CommonConstant.DEL_FLAG_0);
            sysUserService.addUserWithRole(user, customerRoleID);
            sysUserService.addUserWithDepart(user, sysDepart.getId());
            hyCustomer.setUserId(user.getId());
        }else{
            //补充货主部门和角色信息
            SysUser user = sysUserService.getById(hyCustomer.getUserId());
//            if(oConvertUtils.isNotEmpty(customerRoleID)) {
//                String[] arr = customerRoleID.split(",");
//                for (String roleId : arr) {
//                    SysUserRole userRole = new SysUserRole(user.getId(), roleId);
//                    sysUserRoleMapper.insert(userRole);
//                }
//            }
            user.setRealname(uname);
            user.setOrgCode(sysDepart.getOrgCode());
            sysUserService.addUserWithDepart(user, sysDepart.getId());
            sysUserService.updateById(user);
        }
        //保存货主
        hyCustomer.setSysOrgCode(sysDepart.getOrgCode());
        hyCustomer.setOrgId(sysDepart.getId());
        save(hyCustomer);
    }

    @Override
    @Transactional
    public void saveCustomerBatch(List<ImportHyCustomerDTO> hyCustomerDTOList) {

        int index = 1;
        List<HyCustomer> hyCustomerList = new ArrayList<>();
        for (ImportHyCustomerDTO customerDTO : hyCustomerDTOList) {
            HyCustomer hyCustomer = new HyCustomer();
            BeanUtil.copyProperties(customerDTO, hyCustomer, true);

            //如果客户类型=1 个人时，设置客户名称=联系人
            String uname = StrUtil.EMPTY;
            if("1".equals(hyCustomer.getCustomerType())){
                uname = hyCustomer.getCustomerName();
                hyCustomer.setContactName(uname);
                hyCustomer.setIdcard(hyCustomer.getCreditCode());
            }else {
                uname = hyCustomer.getCustomerName();
            }
            //添加部门
            SysDepart sysDepart = new SysDepart();
            sysDepart.setParentId(customerDepartpid);
            sysDepart.setOrgCategory("2");//货主
            sysDepart.setDepartName(uname);
            sysDepart.setDepartOrder(0);
            departService.saveDepartData(sysDepart, uname);

            if(StringUtils.isEmpty(hyCustomer.getUserId())  ){
                //添加用户 ，检查用户是否存在
                SysUser suser = userService.getUserByPhone(hyCustomer.getLoginPhone());
                if(suser != null){
                    throw new JeecgBootException(suser.getPhone() + " 登陆手机号已存在,不能重复注册");
                }

                //添加登陆账号
                SysUser user = new SysUser();
                String username = sysUserService.createRandomUserName();//随机生成账号
                user.setUType("2");
                user.setUsername(username);
                user.setRealname(uname);
                user.setPhone(hyCustomer.getLoginPhone());
                user.setCreateTime(new Date());//设置创建时间
                String salt = oConvertUtils.randomGen(8);
                user.setSalt(salt);
                user.setPassword("Aa.123456");//设置默认密码123456
                String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
                user.setPassword(passwordEncode);
                user.setOrgCode(sysDepart.getOrgCode());
                user.setStatus(1);
                user.setDelFlag(CommonConstant.DEL_FLAG_0);
                sysUserService.addUserWithRole(user, customerRoleID);
                sysUserService.addUserWithDepart(user, sysDepart.getId());
                hyCustomer.setUserId(user.getId());
            }else{
                //补充货主部门和角色信息
                SysUser user = sysUserService.getById(hyCustomer.getUserId());
                user.setRealname(uname);
                user.setOrgCode(sysDepart.getOrgCode());
                sysUserService.addUserWithDepart(user, sysDepart.getId());
                sysUserService.updateById(user);
            }
            //保存货主
            hyCustomer.setSysOrgCode(sysDepart.getOrgCode());
            hyCustomer.setOrgId(sysDepart.getId());
            hyCustomerList.add(hyCustomer);

            log.info("开始导入货主数据， {} / {}", index, hyCustomerDTOList.size());
            index++;
        }

        this.saveBatch(hyCustomerList);
    }


    @Override
    public HyCustomer getCustomerByUserId(String userId) {
        HyCustomer customer = getOne(new QueryWrapper<HyCustomer>().eq("user_id", userId));
        return customer;
    }

    @Override
    public HyCustomer getCustomer(HttpServletRequest req) {
        LoginUser loginUser = UserUtil.getLoginUser();

        String uType = loginUser.getUType();
        HyCustomer customer = null;
        if ("2".equals(uType)) {
            //货主
            customer = getCustomerByUserId(loginUser.getId());
            if(customer == null){
                throw new JeecgBootException("未获取到货主信息");
            }
            if("0".equals(customer.getIzUsed())){
                throw new JeecgBootException("账号已停用");
            }
            if(!"2".equals(customer.getExamineStatus())){
                throw new JeecgBootException("账号正在审核中");
            }
            return customer;
        }else if ("3".equals(uType)){
            HyCustomerUser customerUser = hyCustomerUserService.getOne(new QueryWrapper<HyCustomerUser>().eq("user_id", loginUser.getId()));
            if(customerUser == null){
                throw new JeecgBootException("货主子账号信息不存在");
            }
            if("0".equals(customerUser.getIzUsed())){
                throw new JeecgBootException("账号已停用");
            }
            customer =  getById(customerUser.getCustomerId());
            if(customer == null){
                throw new JeecgBootException("货主信息不存在");
            }
            if("0".equals(customer.getIzUsed())){
                throw new JeecgBootException("账号已停用");
            }
            if(!"2".equals(customer.getExamineStatus())){
                throw new JeecgBootException("账号正在审核中");
            }
            return customer;
        }
        else {
            throw new JeecgBootException("未获取到货主信息");
        }
    }


    /**
     * 组装税务系统发布方（货主）信息
     * @param hyCustomer
     * @return
     */
    private PublisterDTO customer2EnterprisesDTO(HyCustomer hyCustomer){
        PublisterDTO publisterDTO = new PublisterDTO();
        publisterDTO.setFbfuuid(API_TAX_CUSTOMER_SUBFIX + hyCustomer.getId());// 是 平台生成的发布方唯一标识 （uuid 默认长度 32 位，建议 以平台缩写大写字母作为前 缀，并结合数字+字母混合形成 32 位唯一标识）
        publisterDTO.setFbfxm(hyCustomer.getContactName());// 否 发布方（货主）姓名 2019-7-9 说明
        publisterDTO.setFbfsfzjhm(hyCustomer.getIdcard());// 否 发布方（货主）身份证件号码 2019-7-9 说明
        publisterDTO.setYddh(hyCustomer.getLoginPhone());// 否 手机号码 2019-7-9 说明
        publisterDTO.setGjdq("");// 否 国籍（地区）-填写国家地区 代码，参见《申报表-计税 excel 页签：国家和地区代 码》 2019-7-9 说明
        publisterDTO.setQyyddh(hyCustomer.getLoginPhone());// 是 企业手机电话号码
        publisterDTO.setNsrsbh(hyCustomer.getCreditCode());// 是 企业纳税人识别号
        publisterDTO.setNsrmc(hyCustomer.getCustomerName());// 是 企业名称（纳税人名称）
        publisterDTO.setGsdz(hyCustomer.getDetailAddress());// 是 公司地址
        publisterDTO.setXxdz(hyCustomer.getDetailAddress());// 是 详细地址
        publisterDTO.setFddbr(hyCustomer.getLegalName());// 是 法定代表人
        publisterDTO.setZczb(hyCustomer.getZczb());// 是 注册资本

        SimpleDateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
        publisterDTO.setSlrq(dateFormat1.format(hyCustomer.getClrq()));// 是 成立日期 到日

        String code = hyCustomer.getCountyCode().substring(0,4) + "00";
        publisterDTO.setSsdq(code);// 是 所属地区-填写行政区划代 码（市级），参见《行政区划 代码-名称表》 2019-5-1 0 新增 2019-5-1 5 说明
        publisterDTO.setJyfw(hyCustomer.getJyfw());// 是 经营范围

        SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        publisterDTO.setPtzcsj(dateFormat2.format(hyCustomer.getCreateTime()));// 是 企业在平台注册为服务发布方时间 到秒
        publisterDTO.setZgswjg(hyCustomer.getCompetentTaxAuthority());// 是 主管税务机关 2019-5-1 0 新增

        Integer customerType = Integer.parseInt(hyCustomer.getCustomerType()) - 1;
        publisterDTO.setNsrlx(customerType.toString());// 是 企业类型（填写数字代码， 0:一般人/1:小规模） 2019-5-1 0 新增

        String sub = uploadpath + File.separator;
        List imgList = new ArrayList();
        imgList.add(ImageCompressUtil.compressSrcImageToBase64(sub + hyCustomer.getBusinessLicenseImg(),500));
//		 imgList.add(ImageCompressUtil.imageToBase64(sub + hyCustomer.getBusinessLicenseImg2()));
//		 Collections.singletonList(ss)
        publisterDTO.setYyzzfj(imgList);// 是 发布方企业营业执照照片， 照片要求进行 base64转码传输,图片尺寸见补充说明, 图片需要拼接成JSON 数组格式："yyzzfj": ["data:image/jpg;base64, 编码"]
        return publisterDTO;
    }
    @Override
    public ApiBaseResDTO tjTaxUpload(HyCustomer hyCustomer){
        if(hyCustomer == null){
            ApiBaseResDTO apiBaseResDTO = new ApiBaseResDTO();
            apiBaseResDTO.setDesc("货主数据为null！");
            return apiBaseResDTO;
        }
        //1个人 2 公司
        if(hyCustomer.getCustomerType().equals("1")){
            ApiBaseResDTO apiBaseResDTO = new ApiBaseResDTO();
            apiBaseResDTO.setDesc("暂不支持上报个人类型的货主！");
            return apiBaseResDTO;
        }

        PublisterDTO publisterDTO = customer2EnterprisesDTO(hyCustomer);
        ApiBaseResDTO result  =  dongjiangTaxSystemService.sendPublister(publisterDTO);
        Integer code =  StringUtils.isEmpty(result.getCode()) ? 0 : Integer.valueOf(result.getCode()) ;

        hyCustomer.setTjTaxUploadStatus(code >= 100 && code < 200 ? "1":  "2");
        hyCustomer.setTjTaxUploadTime(new Date());
        updateById(hyCustomer);

        return result;
    }

    //快货运 上报托运人
    @Override
    public Result<?> tosUploadCustomer(HyCustomer hyCustomer){
        CustomerDTO customerDTO = new CustomerDTO();
        customerDTO.setName(hyCustomer.getCustomerName());//	托运人名称	是	an..512	企业名称或个人姓名，不能为空，并只允许出现字母数字中文字符，并且字段长度不得超过 512 ，广州@填单位或个人，如集装箱运输业务无法明确实际发货人可填写货代信息，所有企业名称不能超过33个中文字符，
        customerDTO.setPhone(hyCustomer.getLoginPhone());//	企业联系人手机号或者个人手机号	是	n..18
        //个人
        if(hyCustomer.getCustomerType().equals("1")){
            customerDTO.setEnterprise_flag(YNEnum.NO.getCode());//	是否是企业	是		enum (NO, YES)
            customerDTO.setIdentity(hyCustomer.getIdcard());//	个人身份证号	个人必填	an..18
            customerDTO.setIdentity_frontal_pic(tosApiService.uploadFile(hyCustomer.getIdcardImg()));//	身份证正面照图片URL	个人必填	an..1024
            customerDTO.setIdentity_reverse_pic(tosApiService.uploadFile(hyCustomer.getIdcardBackImg()));//	身份证反面照片图片URL	个人必填	an..1024
            //个人类型时户籍地址和常驻地址个人必传一组
            customerDTO.setHousehold_region(hyCustomer.getCountyCode().substring(0,4) + "00");//	户籍地址行政区划		an..12	参考行政区划代码集
            customerDTO.setHousehold_address(hyCustomer.getDetailAddress());//	户籍地址详细地址		an..256
        }else{//企业
            customerDTO.setEnterprise_flag(YNEnum.YES.getCode());//	是否是企业	是		enum (NO, YES)
            customerDTO.setSocial_credit_code(hyCustomer.getCreditCode());//	社会信用代码	企业必填	an..35
            customerDTO.setContacts_name(hyCustomer.getContactName());//	企业联系人	企业选填	an..30
            customerDTO.setBusiness_license_pic(tosApiService.uploadFile(hyCustomer.getBusinessLicenseImg()));//	营业执照图片URL	企业必填	an..1024
            customerDTO.setLegal_person_name(hyCustomer.getLegalName());//	法人姓名	否	an..30

            //企业类型时注册地址和经营地址必传一组
            customerDTO.setRegister_region(hyCustomer.getCountyCode().substring(0,4) + "00");//	注册地址行政区划		an..12	参考行政区划代码集
            customerDTO.setRegister_address(hyCustomer.getDetailAddress());//	注册地址详细地址		an..256
        }
        TosApiBaseResDTO resDTO = tosApiService.subjectCustomer(customerDTO);

        hyCustomer.setTosUploadTime(new Date());
        if(resDTO.isSuccess()){
            hyCustomer.setTosUploadStatus("1");
            this.updateById(hyCustomer);
            return Result.OK("托运人上报成功！");
        }else{
            hyCustomer.setTosUploadStatus("2");
            this.updateById(hyCustomer);
            return Result.error(resDTO.getBiz_message());
        }
    }

    @Override
    @Transactional
    public Result registerCustomer(CustomerSysLoginModel sysLoginModel) {

        HyCustomer hyCustomer = new HyCustomer();
        //如果客户类型=1 个人时，设置客户名称=联系人
        String uname = sysLoginModel.getCustomerName();
        if ("1".equals(sysLoginModel.getCustomerType())) {
            hyCustomer.setIdcard(sysLoginModel.getIdcard());
            hyCustomer.setCustomerName(sysLoginModel.getCustomerName());
            //hyCustomer.setLegalName(sysLoginModel.getCustomerName());
            hyCustomer.setCustomerShoreName(sysLoginModel.getCustomerName());
            hyCustomer.setContactName(sysLoginModel.getCustomerName());
            hyCustomer.setIdcardImg(sysLoginModel.getIdcardImg());
            hyCustomer.setIdcardBackImg(sysLoginModel.getIdcardBackImg());
        } else if ("2".equals(sysLoginModel.getCustomerType())) {
            hyCustomer.setCreditCode(sysLoginModel.getCreditCode());
            hyCustomer.setCustomerName(sysLoginModel.getCustomerName());
            hyCustomer.setCustomerShoreName(sysLoginModel.getCustomerShortName());
            hyCustomer.setBusinessLicenseImg(sysLoginModel.getBusinessLicenseImg());
            hyCustomer.setContactName(sysLoginModel.getContactName());
        } else {
            return Result.error("货主类型选择错误");
        }

        //添加部门
        SysDepart sysDepart = new SysDepart();
        sysDepart.setParentId(customerDepartpid);
        sysDepart.setOrgCategory("2");//货主
        sysDepart.setDepartName(uname);
        sysDepart.setDepartOrder(0);
        this.departService.saveDepartData(sysDepart, uname);

        //添加登陆账号
        SysUser user = new SysUser();
        //随机生成账号
        String username = this.sysUserService.createRandomUserName();
        //货主角色是2
        user.setUType("2");
        user.setUsername(username);
        user.setRealname(uname);
        user.setPhone(sysLoginModel.getPhone());
        user.setCreateTime(new Date());//设置创建时间
        String salt = oConvertUtils.randomGen(8);
        user.setSalt(salt);
        user.setPassword(sysLoginModel.getPassword());
        String passwordEncode = PasswordUtil.encrypt(user.getUsername(), user.getPassword(), salt);
        user.setPassword(passwordEncode);
        user.setOrgCode(sysDepart.getOrgCode());
        user.setStatus(1);
        user.setDelFlag(CommonConstant.DEL_FLAG_0);
        this.sysUserService.addUserWithRole(user, customerRoleID);
        this.sysUserService.addUserWithDepart(user, sysDepart.getId());

        //保存货主登录账号，手机号
        hyCustomer.setLoginPhone(sysLoginModel.getPhone());
        //平台注册默认是来源是1
        hyCustomer.setCustomerChannel("1");
        hyCustomer.setCustomerType(sysLoginModel.getCustomerType());
        hyCustomer.setUserId(user.getId());
        hyCustomer.setSysOrgCode(sysDepart.getOrgCode());
        hyCustomer.setOrgId(sysDepart.getId());
        hyCustomer.setExamineStatus(ExamineStatusEnum.EXAMINE_STATUS_TOREVIEWED.getCode());
        hyCustomer.setCreateTime(user.getCreateTime());
        hyCustomer.setCreateBy(uname);
        if (!this.save(hyCustomer)) {
            throw new JeecgBootException("注册货主失败，创建货主账号时出现错误");
        }

        return Result.OK();
    }
}
